package com.heiye.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heiye.service.ClubService;
import com.heiye.vo.ClubDetailVO;
import com.heiye.vo.ClubShowVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * 社团
 */
@RestController
@RequestMapping("/club")
public class ClubController {

    @Autowired
    private ClubService clubService;

    //获取所有的社团信息(未分页)
    @GetMapping("/selectAllClub")
    public List<ClubShowVO> selectAllClub() {
        return clubService.selectAllClub();
    }


    //根据社团id查找该社团的详细信息
    @GetMapping("/selectClubByCid")
    public ClubDetailVO selectClubByCid(@RequestParam("clubId") int clubId) throws ParseException {
        System.out.println(clubId);
        ClubDetailVO elem = clubService.selectClubByCid(clubId);
        System.out.println(elem.getClubCreateTime());
        //将CST时间格式化输出
        //格式化CST时间
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        //CST时间转字符串
        String dateStr = elem.getClubCreateTime().toString();
        //CST时间字符串转Date类型
        //???? fuck code!
        Date date = (Date) sdf.parse(dateStr);
        //Date类型转换为常用时间类型字符串
        String formatStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
        elem.setClubCreateTime(formatStr);
        return elem;
    }
}
